package com.hyt.it.ogt.kq.service.gov.feign.file;

import com.github.tobato.fastdfs.domain.FileInfo;
import com.hyt.loginfo.config.OAuth2FeignRequestConfig;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * <p>
 *  文件服务Feign客户端
 * </p>
 *
 * @author Chengxh
 * @since 2021-08-14
 */
@FeignClient(name="ogtsc-service-file", fallback = GovFileClientHystrix.class, configuration = OAuth2FeignRequestConfig.class)
public interface GovFileClient {

    /**
     * 上传文件
     * @param file
     * @return
     */
    @RequestMapping(value = "/file/upload/multipartfile", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String uploadFile(@RequestPart(value = "file") MultipartFile file);

    /**
     * 上传文件
     * @param bytes
     * @param format
     * @return
     */
    @RequestMapping(value = "/file/upload/bytes", method = RequestMethod.POST)
    public String uploadFile(@RequestBody byte[] bytes, @RequestParam String format);

    /**
     * 把字符串作为指定格式的文件上传
     * @param content
     * @param fileExtension
     * @return
     */
    @RequestMapping(value = "/file/upload/string", method = RequestMethod.POST)
    public String uploadFile(@RequestParam String content, @RequestParam String fileExtension);

    /**
     *  url 上传文件地址
     * @param url
     * @param fileSize
     * @param fileExtension
     * @return
     */
    @RequestMapping(value = "/file/upload/url", method = RequestMethod.POST)
    public String uploadFileByUrl(@RequestParam String url, @RequestParam long fileSize,@RequestParam String fileExtension);

    /**
     * 上传图片并生成缩略图
     * @param file
     * @return
     */
    @RequestMapping(value = "/file/upload/image/crtthumbimage", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String uploadImageAndCrtThumbImage(@RequestPart(value = "file") MultipartFile file) ;

    /**
     * 根据图片路径获取缩略图路径（使用uploadImageAndCrtThumbImage方法上传图片）
     * @param filePath
     * @return
     */
    @RequestMapping(value = "/file/get/thumbimagepath", method = RequestMethod.GET)
    public String getThumbImagePath(@RequestParam String filePath);

    /**
     * 获取文件信息
     * @param filePath
     * @return
     */
    @RequestMapping(value = "/file/query/fileinfo", method = RequestMethod.GET)
    public FileInfo queryFileInfo(@RequestParam String filePath);

    /**
     * 根据文件路径下载文件
     * @param filePath
     * @return
     */
    @RequestMapping(value = "/file/down", method = RequestMethod.GET)
    public byte[] downFile(@RequestParam String filePath);

    /**
     * 根据文件路径下载文件
     * @param filePath
     * @return
     */
    @RequestMapping(value = "/file/downFileByStream", method = RequestMethod.GET)
    public InputStream downFileByStream(@RequestParam String filePath);

    /**
     * 根据文件地址删除文件
     * @param filePath
     */
    @RequestMapping(value = "/file/delete", method = RequestMethod.DELETE)
    public void deleteFile(@RequestParam String filePath);

}
